package com.liao.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.liao.content.mapper.MovieBaseMapper;
import com.liao.content.mapper.MovieHotMapper;
import com.liao.content.model.dto.MovieBaseHotDto;
import com.liao.content.model.po.MovieBase;
import com.liao.content.model.po.MovieHot;
import com.liao.content.service.MovieHotService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 热门电影表 服务实现类
 * </p>
 *
 * @author liao
 */
@Slf4j
@Service
public class MovieHotServiceImpl extends ServiceImpl<MovieHotMapper, MovieHot> implements MovieHotService {


    @Autowired
    MovieBaseMapper movieBaseMapper;

    @Override
    public List<MovieBaseHotDto> getHotMovieByMt(String categoryId) {
        LambdaQueryWrapper<MovieHot> movieHotLambdaQueryWrapper = new LambdaQueryWrapper<>();
        movieHotLambdaQueryWrapper.eq(MovieHot::getMt,categoryId);
        movieHotLambdaQueryWrapper.orderByDesc(MovieHot::getHot);

        Page<MovieHot> movieBaserPage = new Page<>(1 , 10);

        Page<MovieHot> movieHotPage = this.baseMapper.selectPage(movieBaserPage, movieHotLambdaQueryWrapper);

        List<MovieHot> records = movieHotPage.getRecords();

        List<MovieBaseHotDto> collect = records.stream().map(item -> {

            MovieBase movieBase = movieBaseMapper.selectById(item.getId());
            MovieBaseHotDto movieBaseHotDto = new MovieBaseHotDto();
            BeanUtils.copyProperties(movieBase,movieBaseHotDto);
            movieBaseHotDto.setHot(item.getHot());
            return movieBaseHotDto;
        }).collect(Collectors.toList());



        return collect;
    }
}
